﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Framework_Tool
{
    /// <summary>
    /// Interaction logic for StudentUpdate.xaml
    /// </summary>
    public partial class StudentUpdate : Page
    {
        public StudentUpdate()
        {
            InitializeComponent();
            Database.FindStudentID_Update(this);
            // Database.populateFields_StdtUpdate(this);
        }

        private void viewStudentBtn_Click(object sender, RoutedEventArgs e)
        {
            StudentView stdtViewWindow = new StudentView();
            stdtViewWindow.Content = null;
            mainContent.Children.Add(stdtViewWindow.mainContent);
        }

        private void addStudentBtn_Click(object sender, RoutedEventArgs e)
        {
            StudentAdd stdtAddWindow = new StudentAdd();
            stdtAddWindow.Content = null;
            mainContent.Children.Add(stdtAddWindow.mainContent);
        }

        private void deleteStudentBtn_Click(object sender, RoutedEventArgs e)
        {
            StudentDelete stdtDeleteWindow = new StudentDelete();
            stdtDeleteWindow.Content = null;
            mainContent.Children.Add(stdtDeleteWindow.mainContent);
        }

        private void searchStudentBtn_Click(object sender, RoutedEventArgs e)
        {
            StudentSearch stdtSearchWindow = new StudentSearch();
            stdtSearchWindow.Content = null;
            mainContent.Children.Add(stdtSearchWindow.mainContent);
        }

        private void stdtIDUpdateCmbx_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Database.populateFields_StdtUpdate(this);
            stdtUpdatedLblGrid.Visibility = Visibility.Hidden;
        }

        private void stdtPicBrowse_Click(object sender, RoutedEventArgs e)
        {
            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); // Create OpenFileDialog box

            dlg.DefaultExt = ".jpg"; // Default file extension

            Nullable<bool> result = dlg.ShowDialog(); // Calls ShowDialog method

            if (result == true) // display selected file name in a TextBox
            {
                string filename = dlg.FileName;
                stdtPicTxt.Text = filename;
            }
        }

        private void mainContent_Loaded(object sender, RoutedEventArgs e)
        {
            Database.FindStdtcourseTitle_Update(this);

            viewStudentBtn.FontWeight = FontWeights.Normal;
            addStudentBtn.FontWeight = FontWeights.Normal;
            updateStudentBtn.FontWeight = FontWeights.ExtraBold;
            deleteStudentBtn.FontWeight = FontWeights.Normal;
            searchStudentBtn.FontWeight = FontWeights.Normal;
        }

        private void stdtUpdateBtn_Click(object sender, RoutedEventArgs e)
        {
            Database.UpdateStudent(this);
        }

        private void stdtCourseTitleCmbx_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Database.populateCourseID_Update(this);

            matchStdtPasswordLbl.Visibility = Visibility.Hidden;
            validStdtPasswordLbl.Visibility = Visibility.Hidden;
            stdtEmailValidationLbl.Visibility = Visibility.Hidden;
        }

        private void cancelStdtUpdate_Click_1(object sender, RoutedEventArgs e)
        {
            stdtImage_update.Source = null;
            stdtIDUpdateCmbx.SelectedItem = null;
            stdtFNameTxt.Text = null;
            stdtSurnameTxt.Text = null;
            stdtALine1Txt.Text = null;
            stdtALine2Txt.Text = null;
            stdtCityTxt.Text = null;
            stdtCountyTxt.Text = null;
            stdtPostcodeTxt.Text = null;
            stdtTelNoTxt.Text = null;
            stdtEmailTxt.Text = null;
            stdtPicTxt.Text = null;
            stdtCourseTitleCmbx.SelectedItem = null;
            stdtCourseIDLbl.Content = "Course ID";
            stdtPasswordUpdateTxt.Password = null;
            stdtPassword1UpdateTxt.Password = null;

            stdtUpdatedLblGrid.Visibility = Visibility.Hidden;
            matchStdtPasswordLbl.Visibility = Visibility.Hidden;
            validStdtPasswordLbl.Visibility = Visibility.Hidden;
            stdtEmailValidationLbl.Visibility = Visibility.Hidden;
        }        
    }
}
